package com.wjw.redis.stream.service;

import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class TestAsync {

    @Async("TaskExecutor")
    public void testAsync() {
        String name = Thread.currentThread().getName();
        System.out.println("子线程-线程名称：" + name);

        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            log.error("异步任务执行过程中线程被中断", e); // 提供更多上下文信息
            Thread.currentThread().interrupt(); // 恢复中断状态
        } catch (Exception e) {
            log.error("异步任务执行过程中发生异常", e); // 捕获其他可能的异常
        } finally {
            log.info("子线程结束");
        }
    }

}
